package com.fy56.platform.logistics.service.impl;

import com.fy56.platform.logistics.common.ResultModel;
import com.fy56.platform.logistics.common.ResultStatus;
import com.fy56.platform.logistics.mapper.UserCompanyMapper;
import com.fy56.platform.logistics.model.UserCompany;
import com.fy56.platform.logistics.service.wx.IUserCompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * 用户企业关联Service
 * Created by li on 2018-03-07.
 */
@Service
public class UserCompanyServiceImpl implements IUserCompanyService {

    @Autowired
    private UserCompanyMapper userCompanyMapper;

    @Override
    @Transactional(readOnly = true)
    public List<UserCompany> select(UserCompany entity) {
        return userCompanyMapper.select(entity);
    }

    @Override
    public UserCompany selectByPrimaryKey(Long id) {
        return userCompanyMapper.selectByPrimaryKey(id);
    }

    @Override
    public UserCompany get(UserCompany entity) {
        return null;
    }

    @Override
    @Transactional(readOnly = false)
    public ResultModel insert(UserCompany entity) {
        ResultModel result = null;
        int r = userCompanyMapper.insert(entity);
        if(r == 0) {
            result = ResultModel.error(ResultStatus.INSERT_ERR);
        }else {
            result = ResultModel.ok();
        }
        return result;
    }

    @Override
    public ResultModel insertSelective(UserCompany entity) {
        return null;
    }

    @Override
    @Transactional(readOnly = false)
    public ResultModel update(UserCompany entity) {
        ResultModel result = null;
        int r = userCompanyMapper.updateByPrimaryKey(entity);
        if (r == 0) {
            result = new ResultModel(ResultStatus.EDIT_ERR);
        }else {
            result = ResultModel.ok();
        }
        return result;
    }

    @Override
    @Transactional(readOnly = false)
    public ResultModel updateSelective(UserCompany entity) {
        ResultModel result = null;
        int r = userCompanyMapper.updateByPrimaryKeySelective(entity);
        if (r == 0) {
            result = new ResultModel(ResultStatus.EDIT_ERR);
        }else {
            result = ResultModel.ok();
        }
        return result;
    }

    @Override
    public ResultModel delete(Long id) {
        return null;
    }

    @Override
    @Transactional(readOnly = false)
    public ResultModel delete(UserCompany entity) {
        ResultModel result = null;
        int r = userCompanyMapper.delete(entity);
        if (r == 0) {
            result = new ResultModel(ResultStatus.DELETE_ERR);
        }else {
            result = ResultModel.ok();
        }
        return result;
    }

    @Override
    public List<UserCompany> findList(UserCompany entity) {
        return userCompanyMapper.findList(entity);
    }
}
